import request from '@/utils/request.js'
export function getArticle (aid) {
  return request({
    url: 'articles/' + aid
  })
}

// 加载文章评论
export function getArticleComments (aid, cid) {
  return request({
    url: 'comments',
    params: {
      type: 'a',
      source: aid, // 文章id
      offset: cid // 评论id
    }
  })
}

// 对文章进行点赞或者取消点赞
export function articleLikesOrCancel (aid, isLike) {
  if (isLike) {
    //
    return request({
      url: 'article/likings',
      method: 'post',
      data: {
        target: aid
      }
    })
  } else {
    return request({
      url: 'article/likings/' + aid,
      method: 'delete'
    })
  }
}

// 对文章进行收藏或者取消收藏
export const collectArticle = (articleId, isCollect) => {
  if (isCollect) {
    return request({
      url: 'article/collections',
      method: 'post',
      data: { target: articleId }
    })
  } else {
    return request({
      url: 'article/collections/' + articleId,
      method: 'delete'
    })
  }
}

// 获取评论的 回复
export function getReplysByComment (commentId, offset) {
  return request({
    url: 'comments',
    params: { type: 'c', source: commentId, offset }
  })
}

// 发表一级评论接口
/* eslint-disable camelcase */
export const commentOrReply = (target, content, art_id) => {
  return request({
    url: 'comments',
    method: 'POST',
    data: {
      target,
      content,
      art_id
    }
  })
}
